/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elaborate.tool.messenger.yahoo;

import elaborate.tool.messenger.Message;
import elaborate.tool.messenger.MessengerSender;
import java.net.URLEncoder;

/**
 *
 * @author lendle
 */
public class YahooMessengerSender implements MessengerSender{

    private String oauth_consumer_key;
    private String oauth_token;
    private String consumer_secret;
    private String oauthSecret;
    private String sessionId;
    private String sender;
    private HttpUtil httpUtil=null;

    /**
     * Get the value of sender
     *
     * @return the value of sender
     */
    public String getSender() {
        return sender;
    }

    /**
     * Set the value of sender
     *
     * @param sender new value of sender
     */
    public void setSender(String sender) {
        this.sender = sender;
    }


    /**
     * Get the value of sessionId
     *
     * @return the value of sessionId
     */
    public String getSessionId() {
        return sessionId;
    }

    /**
     * Set the value of sessionId
     *
     * @param sessionId new value of sessionId
     */
    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }


    /**
     * Get the value of oauthSecret
     *
     * @return the value of oauthSecret
     */
    public String getOauthSecret() {
        return oauthSecret;
    }

    /**
     * Set the value of oauthSecret
     *
     * @param oauthSecret new value of oauthSecret
     */
    public void setOauthSecret(String oauthSecret) {
        this.oauthSecret = oauthSecret;
    }

    public String getConsumer_secret() {
        return consumer_secret;
    }

    public void setConsumer_secret(String consumer_secret) {
        this.consumer_secret = consumer_secret;
    }

    /**
     * Get the value of oauth_token
     *
     * @return the value of oauth_token
     */
    public String getOauth_token() {
        return oauth_token;
    }

    /**
     * Set the value of oauth_token
     *
     * @param oauth_token new value of oauth_token
     */
    public void setOauth_token(String oauth_token) {
        this.oauth_token = oauth_token;
    }


    /**
     * Get the value of oauth_consumer_key
     *
     * @return the value of oauth_consumer_key
     */
    public String getOauth_consumer_key() {
        return oauth_consumer_key;
    }

    /**
     * Set the value of oauth_consumer_key
     *
     * @param oauth_consumer_key new value of oauth_consumer_key
     */
    public void setOauth_consumer_key(String oauth_consumer_key) {
        this.oauth_consumer_key = oauth_consumer_key;
    }

    public YahooMessengerSender(String oauth_consumer_key, String consumer_secret, String oauth_token, String oauthSecret, String sessionId, String sender) {
        this.oauth_consumer_key = oauth_consumer_key;
        this.oauth_token = oauth_token;
        this.consumer_secret = consumer_secret;
        this.oauthSecret = oauthSecret;
        this.sessionId = sessionId;
        this.sender = sender;
        //initialize httputil
        this.httpUtil=new HttpUtil(oauth_consumer_key, consumer_secret, oauth_token, oauthSecret, sessionId, sender);
    }
    
    @Override
    public void sendMessage(String destination, Message[] messages) throws Exception {
        for(Message message : messages){
            httpUtil.doPost("http://developer.messenger.yahooapis.com/v1/message/yahoo/"+destination+"?sid=" + sessionId, "{\"message\" : \"" + URLEncoder.encode(message.toString(), "utf-8") + "\"}");
        }
    }
    
}
